<?php 
    
class HouseDAO
{
    private $db;
    public $msg;
    
    public function __construct()
    {
        $this->db = new  DBConfig;
    }
    
 
    public function getAllData()
    {
		$this->db->openConnection();
        $sql = "select * from `abncolourselections`";
        $this->db->query($sql);
        $arr = $this->db->fetch_array();
		$this->db->closeConnection();
        return $arr;   
    }
    
    public function getIndentity()
    {
		$this->db->openConnection();
        $indentity = $this->db->getIndentity();
		$this->db->closeConnection();
		return $indentity;
    }
    
    public function getByemail($email)
    {
		$this->db->openConnection();
        $sql = "select * from `abncolourselections` where `email` = '".$this->db->sqlQuote($email)."' limit 0,1";
		
        $this->db->query($sql);
        $arr = $this->db->fetch_array();
		$this->db->closeConnection();
        return $arr;
    }

 
    
	//insert
    public function insert($House)
    {	
		$this->db->openConnection();

        $sql = "insert into `abncolourselections`(`roof`,`gutter`,`barge_scribe`,`garage`,`main_render`,`paving`,`window_frames`,`gable`,`front_door`,`feature_render`,`feature_wall`,`email`,`id`) values(";
        $sql .= " '".$this->db->sqlQuote($House->getroof())."' ";
        $sql .= ", '".$this->db->sqlQuote($House->getgutter())."' ";
        $sql .= ", '".$this->db->sqlQuote($House->getbarge_scribe())."' ";
		$sql .= ", '".$this->db->sqlQuote($House->getgarage())."' ";
        $sql .= ", '".$this->db->sqlQuote($House->getmain_render())."' ";
        $sql .= ", '".$this->db->sqlQuote($House->getpaving())."' ";
        $sql .= ", '".$this->db->sqlQuote($House->getwindowframes())."' ";
        $sql .= ", '".$this->db->sqlQuote($House->getgable())."' ";
        $sql .= ", '".$this->db->sqlQuote($House->getfront_door())."' ";
        $sql .= ", '".$this->db->sqlQuote($House->getfeature_render())."' ";
		$sql .= ", '".$this->db->sqlQuote($House->getfeature_wall())."' ";
        $sql .= ", '".$this->db->sqlQuote($House->getemail())."' ";
        $sql .= ", '".$this->db->sqlQuote($House->getid())."' ";
        $sql .= " ); ";        
		$this->db->query($sql);
        $result = $this->db->num_affected() != 0? $this->db->getIndentity():0;
		$this->db->closeConnection();
		return $result;
    }
    //update
    public function update($House)
    {
		$this->db->openConnection();
        $sql = "update `abncolourselections` set ";
        $sql .= " `roof` = '".$this->db->sqlQuote($House->getroof())."'  ";
        $sql .= ", `gutter` = '".$this->db->sqlQuote($House->getgutter())."'  ";
        $sql .= ", `barge_scribe` = '".$this->db->sqlQuote($House->getbarge_scribe())."'  ";
		$sql .= ", `garage` = '".$this->db->sqlQuote($House->getgarage())."'  ";
        $sql .= ", `main_render` = '".$this->db->sqlQuote($House->getmain_render())."'  ";
        $sql .= ", `paving` = '".$this->db->sqlQuote($House->getpaving())."'  ";
        $sql .= ", `window_frames` = '".$this->db->sqlQuote($House->getwindowframes())."'  ";
        $sql .= ", `gable` = '".$this->db->sqlQuote($House->getgable())."'  ";
        $sql .= ", `front_door` = '".$this->db->sqlQuote($House->getfront_door())."'  ";
        $sql .= ", `feature_render` = '".$this->db->sqlQuote($House->getfeature_render())."'  ";
		$sql .= ", `feature_wall` = '".$this->db->sqlQuote($House->getfeature_wall())."'  ";
        $sql .= ", `id` = '".$this->db->sqlQuote($House->getid())."'  ";
        $sql .= " where `email` = '".$this->db->sqlQuote($House->getemail())."'";
		
        $this->db->query($sql);
        $result =  $this->db->num_affected() != 0? true:false;
		$this->db->closeConnection();
    }
}
?>